import excel "~Appendix\trump_supplemental_anonymous.xlsx", sheet("Trump+Experiment_October+3%2C+2") firstrow clear


foreach var of varlist d1-d7 c1-c7 t1-t7{
	gen `var'2 = .
	replace `var'2 = 0 if `var' == "Strongly agree"
	replace `var'2 = 0 if `var' == "Strongly Agree"
	replace `var'2 = 1 if `var' == "Agree"
	replace `var'2 = 2 if `var' == "Neither agree nor disagree"
	replace `var'2 = 2 if `var' == "Neither Agree nor disagree"
	replace `var'2 = 3 if `var' == "Disagree"
	replace `var'2 = 4 if `var' == "Strongly disagree"
	replace `var'2 = 4 if `var' == "Strongly Disagree"
}
*
alpha d12-d72
factor d12-d72, ipf factor(1)
rotate, promax
predict preLegit

alpha c12-c72
factor c12-c72, ipf factor(1)
rotate, promax
predict postControl

alpha t12-t72
factor t12-t72, ipf factor(1)
rotate, promax
predict postTreatment

gen controlLegit = postControl - preLegit 
gen treatLegit = postTreatment - preLegit 
egen diffLegit = rowmean(controlLegit treatLegit)


gen treatmentDum = .
replace treatmentDum = 0 if postControl != .
replace treatmentDum = 1 if postTreatment != .

label define treatmentDum 0 "Control" 1 "Treated"
label values treatmentDum treatmentDum

** coded such that high values indicate belief that SC is more politicized
foreach var of varlist p1-p3{
	gen `var'2 = .
	replace `var'2 = 4 if `var' == "Strongly Agree"
	replace `var'2 = 3 if `var' == "Agree"
	replace `var'2 = 2 if `var' == "Neither Agree nor Disagree"
	replace `var'2 = 1 if `var' == "Disagree"
	replace `var'2 = 0 if `var' == "Strongly Disagree"
}
*
alpha p12-p32
factor p12-p32, ipf factor(1)
rotate, promax
predict politicization


gen sc_approval = . 
replace sc_approval = 0 if approval == "Disapprove"
replace sc_approval = 1 if approval == "Approve"


** change in legitimacy regression without controls

reg diffLegit c.trump##i.treatment



foreach var of varlist scideo1 scideo2{
	gen `var'2 = .
	replace `var'2 = 1 if `var' == "Very liberal"
	replace `var'2 = 2 if `var' == "Somewhat liberal"
	replace `var'2 = 3 if `var' == "Moderate"
	replace `var'2 = 4 if `var' == "Somewhat conservative"
	replace `var'2 = 5 if `var' == "Very conservative"
}


gen ideology = .
replace ideology = 1 if self == "Extremely liberal"
replace ideology = 2 if self == "Liberal"
replace ideology = 2 if self == "Slightly liberal"
replace ideology = 3 if self == "Moderate"
replace ideology = 4 if self == "Slightly conservative"
replace ideology = 4 if self == "Conservative"
replace ideology = 5 if self == "Extremely conservative"


gen preIdeoDiff = 0
replace preIdeoDiff = 1 if scideo12 ==1 & ideology ==2 
replace preIdeoDiff = 1 if scideo12 ==2 & ideology ==1 
replace preIdeoDiff = 1 if scideo12 ==2 & ideology ==3 
replace preIdeoDiff = 1 if scideo12 ==3 & ideology ==2 
replace preIdeoDiff = 1 if scideo12 ==3 & ideology ==4 
replace preIdeoDiff = 1 if scideo12 ==4 & ideology ==3 
replace preIdeoDiff = 1 if scideo12 ==4 & ideology ==5 
replace preIdeoDiff = 1 if scideo12 ==5 & ideology ==4 

replace preIdeoDiff = 2 if scideo12 ==1 & ideology ==3 
replace preIdeoDiff = 2 if scideo12 ==2 & ideology ==4 
replace preIdeoDiff = 2 if scideo12 ==3 & ideology == 1
replace preIdeoDiff = 2 if scideo12 ==3 & ideology == 5
replace preIdeoDiff = 2 if scideo12 ==4 & ideology ==2 
replace preIdeoDiff = 2 if scideo12 ==5 & ideology ==3

replace preIdeoDiff = 3 if scideo12 ==1 & ideology ==4 
replace preIdeoDiff = 3 if scideo12 ==2 & ideology ==5 
replace preIdeoDiff = 3 if scideo12 ==4 & ideology ==1 
replace preIdeoDiff = 3 if scideo12 ==5 & ideology ==2

replace preIdeoDiff = 4 if scideo12 == 1& ideology ==5 
replace preIdeoDiff = 4 if scideo12 ==5 & ideology == 1  




gen postIdeoDiff = 0
replace postIdeoDiff = 1 if scideo22 ==1 & ideology ==2 
replace postIdeoDiff = 1 if scideo22 ==2 & ideology ==1 
replace postIdeoDiff = 1 if scideo22 ==2 & ideology ==3 
replace postIdeoDiff = 1 if scideo22 ==3 & ideology ==2 
replace postIdeoDiff = 1 if scideo22 ==3 & ideology ==4 
replace postIdeoDiff = 1 if scideo22 ==4 & ideology ==3 
replace postIdeoDiff = 1 if scideo22 ==4 & ideology ==5 
replace postIdeoDiff = 1 if scideo22 ==5 & ideology ==4 

replace postIdeoDiff = 2 if scideo22 ==1 & ideology ==3 
replace postIdeoDiff = 2 if scideo22 ==2 & ideology ==4 
replace postIdeoDiff = 2 if scideo22 ==3 & ideology == 1
replace postIdeoDiff = 2 if scideo22 ==3 & ideology == 5
replace postIdeoDiff = 2 if scideo22 ==4 & ideology ==2 
replace postIdeoDiff = 2 if scideo22 ==5 & ideology ==3

replace postIdeoDiff = 3 if scideo22 ==1 & ideology ==4 
replace postIdeoDiff = 3 if scideo22 ==2 & ideology ==5 
replace postIdeoDiff = 3 if scideo22 ==4 & ideology ==1 
replace postIdeoDiff = 3 if scideo22 ==5 & ideology ==2

replace postIdeoDiff = 4 if scideo22 == 1& ideology ==5 
replace postIdeoDiff = 4 if scideo22 ==5 & ideology == 1  

*** coded such that larger values indicate
*** that the difference has grown, and 
*** smaller values indicate the distance between
*** oneself and the perceived position of the Court
*** has shrunk
gen ideoDiff = postIdeoDiff - preIdeoDiff


rename pid partyid
gen pid = .
replace pid = 1 if partyid == "Democrat" & strong_d == "Strong"
replace pid = 2 if partyid == "Democrat" & strong_d == "Not very strong"
replace pid = 3 if partyid == "Independent" & leaner == "Democratic Party"
replace pid = 4 if partyid == "Independent" & leaner == "Neither"
replace pid = 4 if partyid == "Other" & leaner == "Neither"
replace pid = 5 if partyid == "Independent" & leaner == "Republican party"
replace pid = 6 if partyid == "Republican" & strong_r == "Not very strong"
replace pid = 7 if partyid == "Republican" & strong_r == "Strong"

gen female = .
replace female = 0 if gender == "Male"
replace female = 1 if gender == "Female"


gen eduCat = .
replace eduC = 0 if educat == "Did not graduate high school"
replace eduC = 1 if educat == "High school diploma or equivalent (GED)"
replace eduC = 2 if educat == "Some college but no degree"
replace eduC = 3 if educat == "Bachelor's degree (BA, MS, BSW, etc.)"
replace eduC = 4 if educat == "Graduate degree (MA, MS, MSW, MD, PhD, etc.)"


sort treatment
by treatment: sum female
by treatment: sum eduC
by treatment: sum trump
by treatment: sum scotus
by treatment: sum preIdeoD
by treatment: sum ideology
by treatment: sum pid

egen min = min(politic)
egen max = max(politic) 
replace politic = ((politic - min)/(max-min))
drop min max

by treatment: sum politic



replace age = "30" if age == "3O"
destring age, gen(age1)

by treatment: sum age1
